//
//  LGNewFeatrueCell.m
//  微博
//
//  Created by MS on 15-12-5.
//  Copyright (c) 2015年 MS. All rights reserved.
//

#import "LGNewFeatrueCell.h"
#import "LGTabbarController.h"
@interface LGNewFeatrueCell ()

@property (nonatomic,weak) UIImageView * imageView;
@property (nonatomic,weak) UIButton * share;
@property (nonatomic,weak) UIButton * start;

@end

@implementation LGNewFeatrueCell

-(UIButton *)share
{
    if (!_share) {
        UIButton * share = [UIButton buttonWithType:UIButtonTypeCustom];
        [share setImage:[UIImage imageNamed:@"new_feature_share_false"] forState:UIControlStateNormal];
        [share setImage:[UIImage imageNamed:@"new_feature_share_true"] forState:UIControlStateSelected];
        [share setTitle:@"分享给大家" forState:UIControlStateNormal];
        [share setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [share sizeToFit];
        
        [share addTarget:self action:@selector(shareClick:) forControlEvents:UIControlEventTouchUpInside];
        
        [self.contentView addSubview:share];
        
        _share = share;
    }
    return _share;
}

-(UIButton *)start
{
    if (!_start) {
        UIButton * start = [UIButton buttonWithType:UIButtonTypeCustom];
        
        [start setBackgroundImage:[UIImage imageNamed:@"new_feature_finish_button"] forState:UIControlStateNormal];
        [start setBackgroundImage:[UIImage imageNamed:@"new_feature_finish_button_highlighted"] forState:UIControlStateHighlighted];
        [start setTitle:@"开始微博" forState:UIControlStateNormal];
        
        [start sizeToFit];
        [start addTarget:self action:@selector(startClick) forControlEvents:UIControlEventTouchUpInside];
        
        [self.contentView addSubview:start];
        _start = start;
    }
    
    return _start;
}

-(UIImageView *)imageView
{
    if (!_imageView) {
        UIImageView * imageV = [[UIImageView alloc] init];
        
        _imageView = imageV;
        
        //注意：一定要加到contenview
        [self.contentView addSubview:imageV];
        
    }
    
    return _imageView;
    
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    
    self.imageView.frame = self.bounds;
    
    self.share.center = CGPointMake(self.bounds.size.width * 0.5, self.bounds.size.height * 0.8);
    
    self.start.center =CGPointMake(self.bounds.size.width * 0.5, self.bounds.size.height * 0.88);
}

-(void)setImage:(UIImage *)image
{
    _image = image;
    
    
    self.imageView.image = image;
}

-(void) startClick
{
    UIWindow * window = [UIApplication sharedApplication].keyWindow;
    
    LGTabbarController * tabBar = [[LGTabbarController alloc] init];
    
    window.rootViewController =tabBar;
    
}

-(void) shareClick:(UIButton *)button
{
    button.selected = !button.selected;
    
}

-(void) setIndexPath:(NSIndexPath *)indexPath count:(int) count
{
    
    if (indexPath.row ==count-1) {
        self.share.hidden = NO;
        self.start.hidden = NO;
    }else
    {
        self.share.hidden = YES;
        self.start.hidden = YES;
    }

}
@end
